use "C:\Users\blake.emidy\OneDrive - The University of Montana\FEVS 2020\FEVS_2020_Clean_7-6-21.dta", clear

factor V17_* [aw=post], pcf // "Before" Performance Measures
alpha V17_*, item // .95 alpha
egen befmiss = rowmiss(V17_*)
egen perf19bef = rmean(V17_*) if befmiss<4
label var perf19bef "Average Work Unit Performance BEFORE Pandemic"

factor V18_* [aw=post], pcf // "During" Performance Measures
alpha V18_*, item // .95 alpha
egen durmiss = rowmiss(V18_*)
egen perf19dur = rmean(V18_*) if durmiss<4
label var perf19dur "Average Work Unit Performance DURING Pandemic"

recode agcy 32=0

tab1 V2A V2B V2C
tab1 V2A V2B V2C, nol

clonevar before = V2A
clonevar peak = V2B
clonevar asofnow = V2C

recode before (4=0) (5=4) // also making "physically present" the ref group
tab before V2A, m 

recode peak (4=0) (5=4) // also making "physically present" the ref group
tab peak V2B, m 

recode asofnow (4=0) (5=4) // also making "physically present" the ref group
tab asofnow V2C, m 

label define covid4 0 "I do not telework because I have to be physically present on the job" 1 "I telework 3 or more days a week" ///
 2 "I telework 2 or fewer days a week or infrequently" 3 "I do not telework because I have barriers (technical issues, did not receive approval)" 4 "I do not telework because I choose not to telework"	//
label values before covid4
label values peak covid4
label values asofnow covid4

drop D*
drop Z*

tab Q36 // job sat; still single-item
clonevar jobsat = Q36

tab leavebe leavenow, row col
tab leavenow // as of survey period, intending to leave

mark ingram
markout ingram jobsat decline19 V13_02 V13_03 race male fedten super over40 agcy disability asofnow V16
keep if ingram==1

tab V13_02 V13_03 [aw=post], cell
tab V13_02 V13_03 [aw=post], row col nofr


clonevar c19comm = V13_01
recode c19comm (3=1)
clonevar c19train = V13_02
recode c19train (3=1)
clonevar c19resour = V13_03
recode c19resour (3=1)
clonevar c19transp = V13_04
recode c19transp (3=1)
clonevar c19trav = V13_05
recode c19trav (3=1)
clonevar c19reminfo = V13_06
recode c19reminfo (3=1)
clonevar c19remtr = V13_07
recode c19remtr (3=1)
clonevar c19remeq = V13_08
recode c19remeq (3=1)
clonevar c19collab = V13_09
recode c19collab (3=1)
clonevar c19remapps = V13_10
recode c19remapps (3=1)
clonevar c19it = V13_11
recode c19it (3=1)
clonevar c19data = V13_12
recode c19data (3=1)
tab1 c19* [aw=post]

gen stayingnow = .
replace stayingnow = 1 if leavenow==1
replace stayingnow = 0 if leavenow==2
replace stayingnow = 0 if leavenow==3
replace stayingnow = 0 if leavenow==4
tab stayingnow leavenow

gen stayingbe = .
replace stayingbe = 1 if leavebe==1
replace stayingbe = 0 if leavebe==2
replace stayingbe = 0 if leavebe==3
replace stayingbe = 0 if leavebe==4
tab stayingbe leavebe

gen changedstay = .
replace changedstay = 100 if stayingbe==1 & stayingnow==0
replace changedstay = 0 if stayingbe==0 & stayingnow==0
replace changedstay = 0 if stayingbe==1 & stayingnow==1
replace changedstay = 0 if stayingbe==0 & stayingnow==1

gen changedup = .
replace changedup = 1 if stayingbe==1 & stayingnow==0 // staying before, leaving now
replace changedup = 3 if stayingbe==0 & stayingnow==0 // leaving before, leaving now
replace changedup = 0 if stayingbe==1 & stayingnow==1 // staying before, staying now
replace changedup = 2 if stayingbe==0 & stayingnow==1 // leaving before, staying now
label var changedup "Chg. in Turnover Intention"
label define chgup 0 "Staying before, staying now" 1 "Staying before, leaving now" 2 "Leaving before, staying now" 3 "Leaving before, leaving now"
label val changedup chgup
tab changedup, m

gen netchg = .
replace netchg = -100 if (changedup==1)
replace netchg = 100 if (changedup==2)
replace netchg = 0 if (changedup==0)
replace netchg = 0 if (changedup==3)
label var changedup "Change in Turnover Intention"
label define ntup2 0 "No Change" -100 "Staying before, leaving now" 100 "Leaving before, staying now"
label val netchg ntup2
tab netchg changedup

gen threedays = .
replace threedays = 0 if (asofnow==0)
replace threedays = 0 if (asofnow==2)
replace threedays = 0 if (asofnow==3)
replace threedays = 0 if (asofnow==4)
replace threedays = 1 if (asofnow==1)
tab threedays asofnow, m






**** Post-TAD Analysis -- using 

sum V16 [aw=post]
gen zerodemands = V16 - 3.554108
sum V16 zerodemands [aw=post]

recode V13_02 (3=0)
recode V13_03 (3=0)


***** Last set of commands prior to sending this out *****

sum Q36 [aw=post]
gen zerojs = Q36 - 3.850395

sum Q37 [aw=post]
gen zerops = Q37 - 3.695888

mvreg perf19bef perf19dur = i.V13_02 i.V13_03 zerodemands zerojs zerops i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
lincom [perf19bef]2.V13_02 - [perf19dur]2.V13_02
lincom [perf19bef]1.V13_02 - [perf19dur]1.V13_02
lincom ([perf19bef]1.V13_02 - [perf19dur]1.V13_02) - ([perf19bef]2.V13_02 - [perf19dur]2.V13_02)
lincom [perf19bef]2.V13_03 - [perf19dur]2.V13_03
lincom [perf19bef]1.V13_03 - [perf19dur]1.V13_03
lincom ([perf19bef]1.V13_03 - [perf19dur]1.V13_03) - ([perf19bef]2.V13_03 - [perf19dur]2.V13_03)
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\PerformMVReg_8-10-22.xls", label tstat excel  dec(3) append
quietly mvreg perf19bef perf19dur = i.V13_02 i.V13_03 zerodemands i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\PerformMVReg_NoStars_8-10-22.xls", label tstat excel noast  append


mvreg perf19bef perf19dur = i.V13_02 i.V13_03 zerodemands 1.V13_02#c.zerodemands 2.V13_02#c.zerodemands zerojs zerops i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
lincom [perf19bef]2.V13_02#c.zerodemands - [perf19dur]2.V13_02#c.zerodemands
lincom [perf19bef]1.V13_02#c.zerodemands - [perf19dur]1.V13_02#c.zerodemands
lincom ([perf19bef]2.V13_02#c.zerodemands - [perf19dur]2.V13_02#c.zerodemands) - ([perf19bef]1.V13_02#c.zerodemands - [perf19dur]1.V13_02#c.zerodemands)
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\PerformMVReg_8-10-22.xls", label tstat excel  dec(3) append
quietly mvreg perf19bef perf19dur = i.V13_02 i.V13_03 zerodemands 1.V13_02#c.zerodemands 2.V13_02#c.zerodemands i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\PerformMVReg_NoStars_8-10-22.xls", label tstat excel noast  append

margins, dydx(zerodemands) at(V13_02=(1 2))
margins, at(zerodemands=(-2.554108(1)1.445892) V13_02=(1 2)) 
marginsplot, recast(line) recastci(rarea) ciopts(color(*.6))

di -.0307968/-.0538927 

mvreg perf19bef perf19dur = i.V13_02 i.V13_03 zerodemands 1.V13_03#c.zerodemands 2.V13_03#c.zerodemands zerojs zerops i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
lincom [perf19bef]2.V13_03#c.zerodemands - [perf19dur]2.V13_03#c.zerodemands
lincom [perf19bef]1.V13_03#c.zerodemands - [perf19dur]1.V13_03#c.zerodemands
lincom ([perf19bef]2.V13_03#c.zerodemands - [perf19dur]2.V13_03#c.zerodemands) - ([perf19bef]1.V13_03#c.zerodemands - [perf19dur]1.V13_03#c.zerodemands)
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\PerformMVReg_8-10-22.xls", label tstat excel  dec(3) append
quietly mvreg perf19bef perf19dur = i.V13_02 i.V13_03 zerodemands 1.V13_03#c.zerodemands 2.V13_03#c.zerodemands i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\PerformMVReg_NoStars_8-10-22.xls", label tstat excel noast  append

margins, dydx(zerodemands) at(V13_03=(1 2))
margins, at(zerodemands=(-2.554108(1)1.445892) V13_03=(1 2)) 
marginsplot, recast(line) recastci(rarea) ciopts(color(*.6))

di -.029224/-.0515191 

mvreg stayingbe stayingnow = i.V13_02 i.V13_03 zerodemands zerojs zerops i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
lincom [stayingbe]2.V13_02 - [stayingnow]2.V13_02
lincom [stayingbe]1.V13_02 - [stayingnow]1.V13_02
lincom ([stayingbe]1.V13_02 - [stayingnow]1.V13_02) - ([stayingbe]2.V13_02 - [stayingnow]2.V13_02)
lincom [stayingbe]2.V13_03 - [stayingnow]2.V13_03
lincom [stayingbe]1.V13_03 - [stayingnow]1.V13_03
lincom ([stayingbe]1.V13_03 - [stayingnow]1.V13_03) - ([stayingbe]2.V13_03 - [stayingnow]2.V13_03)
lincom [stayingbe]zerodemands - [stayingnow]zerodemands
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\StayMVReg_8-10-22.xls", label tstat excel  dec(3) append
quietly mvreg stayingbe stayingnow = i.V13_02 i.V13_03 zerodemands i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\StayMVReg_NoStars_8-10-22.xls", label tstat excel noast  append

mvreg stayingbe stayingnow = i.V13_02 i.V13_03 zerodemands 1.V13_02#c.zerodemands 2.V13_02#c.zerodemands zerojs zerops i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
lincom [stayingbe]2.V13_02#c.zerodemands - [stayingnow]2.V13_02#c.zerodemands
lincom [stayingbe]1.V13_02#c.zerodemands - [stayingnow]1.V13_02#c.zerodemands
lincom ([stayingbe]2.V13_02#c.zerodemands - [stayingnow]2.V13_02#c.zerodemands) - ([stayingbe]1.V13_02#c.zerodemands - [stayingnow]1.V13_02#c.zerodemands)
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\StayMVReg_8-10-22.xls", label tstat excel  dec(3) append
quietly mvreg stayingbe stayingnow = i.V13_02 i.V13_03 zerodemands 1.V13_02#c.zerodemands 2.V13_02#c.zerodemands i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\StayMVReg_NoStars_8-10-22.xls", label tstat excel noast  append

margins, dydx(zerodemands) at(V13_02=(1 2))
margins, at(zerodemands=(-2.554108(1)1.445892) V13_02=(1 2)) 
marginsplot, recast(line) recastci(rarea) ciopts(color(*.6))

di -.0130621/-.0189801 

mvreg stayingbe stayingnow = i.V13_02 i.V13_03 zerodemands 1.V13_03#c.zerodemands 2.V13_03#c.zerodemands zerojs zerops i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
lincom [stayingbe]2.V13_03#c.zerodemands - [stayingnow]2.V13_03#c.zerodemands
lincom [stayingbe]1.V13_03#c.zerodemands - [stayingnow]1.V13_03#c.zerodemands
lincom ([stayingbe]2.V13_03#c.zerodemands - [stayingnow]2.V13_03#c.zerodemands) - ([stayingbe]1.V13_03#c.zerodemands - [stayingnow]1.V13_03#c.zerodemands)
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\StayMVReg_8-10-22.xls", label tstat excel  dec(3) append
quietly mvreg stayingbe stayingnow = i.V13_02 i.V13_03 zerodemands 1.V13_03#c.zerodemands 2.V13_03#c.zerodemands i.asofnow i.race male i.fedten i.super over40 i.agcy disability [aw=post], corr
outreg2 using "C:\Users\blake.emidy\OneDrive - The University of Montana\HRM2020 Research\StayMVReg_NoStars_8-10-22.xls", label tstat excel noast  append

margins, dydx(zerodemands) at(V13_03=(1 2))
margins, at(zerodemands=(-2.554108(1)1.445892) V13_03=(1 2)) 
marginsplot, recast(line) recastci(rarea) ciopts(color(*.6))

di -.0130501/-.019277 







